#!/bin/bash

########################
#@title 46代码同步
#@build lixiaocheng
#@date  2016-04-11
########################

ip="192.168.1.46"
read -p "请输入服务器${ip}的root密码:
" passwd


#-----------------
# myRsync
# @param $1 from /www/a.txt
# @param $2 to root@192.168.1.210:/www/a.txt
function myRsync(){
	#echo "rsync -avrz $1 $2 --exclude=*.svn --exclude=*.log"
	/usr/bin/expect << EOF
		spawn /usr/bin/rsync  -avrz $1 $2 --exclude=*.svn --exclude=*.log
		expect {
			"*yes/no" { send "yes\r"; exp_continue }
			"*password:" { send "$passwd\r" }
		}
		expect eof
EOF
}



#同步各个SVN的项目
list=`ls -l /www|grep '^d'|awk '{print $9}'`
for li in $list
do 
    if [ -d $li -a -d ${li}/.svn ]; then
		myRsync /www/${li}/ root@${ip}:/www/${li}/
    fi
done


#修改/etc/hosts
\cp /etc/hosts /tmp/hosts
sed -i 's/192.168.1.44/192.168.1.46/g' /tmp/hosts
sed -i 's/ shopdev/ shopdev_46/g' /tmp/hosts

#同步/www/include/  /usr/local/nginx/conf/vhost/  /tmp/hosts 等文件
rsync_dir="/www/include/ /usr/local/nginx/conf/vhost/ /tmp/hosts"
for li in $rsync_dir
do
	myRsync ${li} root@${ip}:${li}
done




